import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

export const typeOrmConfig = (configService:ConfigService): TypeOrmModuleOptions => ({
    type: 'mysql',
    host: configService.get<string>('DB_HOST'),
    port: configService.get<number>('DB_PORT'),
    username: configService.get<string>('DB_USERNAME'),
    password: configService.get<string>('DB_PASSWORD'),
    database: configService.get<string>('DB_DATABASE'),
    entities: [__dirname + '/../**/*.entity{.ts,.js}'],
    // 可以打印出执行的sql语句
    logging: configService.get<string>('NODE_ENV') !== 'production',
    // 定义的实体自动生成到数据库表里，但是绝对不能用于生产环境下
    synchronize: configService.get<string>('NODE_ENV') !== 'production',
})